<template>
  <div>
    <el-breadcrumb separator="/">
      <el-breadcrumb-item :to="{ path: '/welcome' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>调拨管理</el-breadcrumb-item>
      <el-breadcrumb-item>物资流向</el-breadcrumb-item>
    </el-breadcrumb>
    <el-card class="box-card">
      <el-table stripe :data="List" style="width: 100%">
        <el-table-column prop="id" type="index" label="ID" width="50"></el-table-column>
        <el-table-column prop="receiver" label="收货人" width="180"></el-table-column>
        <el-table-column prop="currentAddress" label="当前地址"></el-table-column>
        <el-table-column prop="address" label="收货地址"></el-table-column>
        <el-table-column prop="state" label="签收状态"></el-table-column>
        <el-table-column prop="tId" label="调拨编号"></el-table-column>
        <el-table-column label="操作" fixed="right" width="120">
          <template slot-scope="scope">
            <el-button type="text" size="mini" icon="el-icon-edit" @click="openEditUser(scope.row)">编辑</el-button>
            <el-button type="text" size="mini" icon="el-icon-delete" @click="del(scope.row.id)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
        :current-page="queryInfo.page"
        :page-sizes="[5, 10, 15, 30]"
        :page-size="queryInfo.size"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total">
      </el-pagination>
    </el-card>
    <el-dialog title="修改签收信息" :visible.sync="editDialogVisible" width="50%" @close="closeEdit" >
      <el-form :model="editForm" :rules="rulesAdd" ref="ruleFormEdit" label-width="100px">
        <el-form-item label="签收状态" prop="state">
          <el-input v-model="editForm.state"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
          <el-button @click="editDialogVisible = false">取 消</el-button>
          <el-button type="primary" @click="edit">确 定</el-button>
        </span>
    </el-dialog>
  </div>
</template>

<script>
export default {
  name: 'Flow',
  mounted () {
    this.getList()
  },
  methods: {
    search () {
      this.queryMap.pageNum = 1
      this.getConsumerList()
    },
    openEditUser (userInfo) {
      this.editForm = userInfo
      this.editDialogVisible = true
    },
    async edit () {
      const { data: res } = await this.$http.put('flow', this.editForm)
      if (res.code !== 200) {
        this.$message.error(res.msg)
        return false
      }
      await this.getList()
      this.$message.success(res.msg)
      this.editDialogVisible = false
    },
    del (id) {
      this.$confirm('此操作将永久删除, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(async () => {
        const { data: res } = await this.$http.delete('flow/' + id)
        if (res.code !== 200) {
          return this.$message.error(res.msg)
        }
        await this.getList()
        this.$message({
          type: 'success',
          message: '删除成功!'
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    },
    closeEdit () {
      this.$refs.ruleFormEdit.resetFields()
    },
    async getList () {
      const { data: res } = await this.$http.get('flow', { params: this.queryInfo })
      if (res.code !== 200) {
        return this.$message.error(res.msg)
      }
      this.List = res.data.result
      this.total = res.data.total
    },
    handleSizeChange (val) {
      this.queryInfo.size = val
      this.getList()
    },
    handleCurrentChange (val) {
      this.queryInfo.page = val
      this.getList()
    }
  },
  data () {
    return {
      rulesAdd: { state: [{ required: true, message: '请输入签收状态', trigger: 'blur' }] },
      total: 0,
      queryInfo: { username: '', page: 1, size: 10 },
      List: [],
      editForm: {},
      editDialogVisible: false
    }
  }
}
</script>

<style scoped>

</style>
